<template>
  <view class="splash">
    <image :src="images"  :style="{width:windowWidth + 'px' ,height:windowHeight+'px'}"  ></image>
<!--    <view class="time" :style="{'top':statusBarHeight + 'px'}">{{countDown}}s</view>-->
<!--    <view class="skip" v-if="showSkip" @click="skip">跳过广告</view>-->
  </view>
</template>

<script>
import { mapGetters } from 'vuex';
import { toLogin } from '@/libs/login.js';
export default {
  computed: mapGetters(['isLogin']),
  data() {
    return {
      images:this.$common.imgUrl() +'/images/welcome.png',
      // images:'https://s11.ax1x.com/2024/01/15/pFiNtun.png',
      showSkip: false, // 是否显示跳过广告按钮
      countDown: 0, // 倒计时
      windowWidth:0,
      windowHeight:0,
      statusBarHeight:0
    };
  },
  onLoad(){
    let that = this
    wx.getSystemInfo({
      success: res => {
        that.statusBarHeight = res.statusBarHeight;
        that.windowHeight = res.windowHeight;
        that.windowWidth = res.windowWidth;
      }
    })
  },
  onShow() {
    this.launchApp();
  },
  methods: {
    launchApp() {
      console.log('------------登录状态',this.isLogin)
      if (!this.isLogin)
      {
        return toLogin();
      }else {
        let water_role = uni.getStorageSync('USER_INFO_ROLE');
        let url = '';
        if (water_role=="manage"){
          url = '/pages/user/index';
        }else if (water_role=="buy"){
          url = '/pages/user/index';
        }else if (water_role=="intake"){
          url = '/pages/index/home';
        }else {
          url = '/pages/index/home';
        }
        

        console.log('url',url)
        uni.reLaunch({
          url: url,
          success(){
          },
          fail() {
            console.log('失败了吗')
          }
        })
      }
    } ,

    /**
     * 展示广告,轮播图片地址可通过接口获取,具体自己实现
     */
    showAd() {
      this.countDown = 5; // 设置倒计时时间
      // this.startCountDown(); // 开始倒计时
    },
    /**
     * 倒计时跳转展示跳过按钮
     */
    startCountDown() {
      const that = this
      setInterval(() => {
        if (that.countDown > 0) {
          that.countDown--;
          console.log("that.countDown",that.countDown)
          if (that.countDown <= 3) {
            that.showSkip = true; // 显示跳过广告按钮
          }
        } else {
          const value = uni.getStorageSync('launchFlag');
          that.launchApp()
        }
      }, 1000);
    },
  },
};
</script>

<style>
.splash {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
.splash .time {
  position: absolute;
  top: 20px;
  left: 20px;
  font-size: 14px;
  color: #fff;
  background-color: rgba(0, 0, 0, 0.5);
  padding: 5px 10px;
  border-radius: 20px;
}
.splash .skip {
  position: absolute;
  bottom: 20px;
  right: 20px;
  font-size: 12px;
  color: #fff;
  background-color: rgba(0, 0, 0, 0.5);
  padding: 5px 10px;
  border-radius: 15px;
  cursor: pointer;
  z-index: 999;
}
</style>
